package com.hqj.demo01;

import javax.sound.midi.Soundbank;

public class Test02 {

    public static void main(String[] args) {
        //声明子类对象
        //Man m = new Man();

        //多态性
        People p = new People();//自身创建
        //p.run();
        Man p1 = new Man();//子类创建
        //p1.run();//子类
        Women p2 = new Women();//子类创建
        //p2.createBaby();//父类无法使用子类自己的方法(非继承的方法)

        Message m = new Message();
        m.getPeople(p2);

    }
}

class People extends Object{
    private String name;
    private String sex;
    private int age;

    public People() {
        super();
        System.out.println("父类的构造方法");
    }

    public void run(){
        System.out.println("父类的run");
    }
}

class Man extends People{
    private String hz;

    public Man() {
        super();//隐藏的super
        System.out.println("子类Man的构造方法");
    }

    @Override
    public void run() {
        System.out.println("子类的run");
    }

    public void drink(){
        System.out.println("可以无中指的喝");
    }
}

class Women extends People{


    public void createBaby(){
        System.out.println("子类方法");
    }
}

class Message{


    public void getPeople(People people){//参数的多态性
        System.out.println("招工");
        if(people instanceof Man){
            Man m = (Man)people;
            m.drink();
        }else if(people instanceof Women){
            Women w = (Women)people;
            w.createBaby();
        }

    }

}
